//
//  RadioDetailViewController.m
//  宝宝儿歌
//
//  Created by student on 16/4/19.
//  Copyright © 2016年 baobaoerge. All rights reserved.
//

#import "RadioDetailViewController.h"

#import "ModelSingleton.h"
#import "RadioModelCell.h"
#import "RadioModel.h"
#import "RadioModelListInfo.h"
#import "VoicePlayer.h"
#import <UIImageView+WebCache.h>
#import "VoicePlayViewController.h"
@interface RadioDetailViewController ()

@property (nonatomic, strong) NSArray *list;
@property (nonatomic, strong) NSString *soundId;

@end

@implementation RadioDetailViewController

- (NSArray *)list
{
    if (_list ==nil) {
        _list = [[NSArray alloc] init];
    }
    return _list;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"%@",self.radioModelLink);
    [RadioModelListInfo radioModelListInfo:self.radioModelLink successBlok:^(NSArray *imgList) {
        self.list = imgList;
        [self.tableView reloadData];
    } failBlok:^(NSError *error) {
        
    }];
    //图片表头
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.bounds.size.width/10, 0, self.view.bounds.size.width/5*4, self.view.bounds.size.height/3)];
    [imageView sd_setImageWithURL:[NSURL URLWithString:self.radioImage] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    
    self.tableView.rowHeight = 90;
    self.tableView.tableHeaderView = imageView;
    UINib *nib = [UINib nibWithNibName:@"RadioModelCell" bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:@"radioModelCell"];


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.list.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    RadioModelCell *cell = [tableView dequeueReusableCellWithIdentifier:@"radioModelCell" forIndexPath:indexPath];
    NSDictionary *dict = self.list[indexPath.row];
    RadioModel *radioModel = [RadioModel radioModelWithDictionary:dict];
    cell.timesLabel.text = radioModel.radioTimes;
    cell.titelLabel.text = radioModel.radioTitle;
    cell.dateLabel.text = radioModel.radioDate;

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    NSDictionary *dict = self.list[indexPath.row];
    RadioModel *currentRadioModel = [RadioModel radioModelWithDictionary:dict];
    currentRadioModel.radioImage = self.radioImage;
    
    [VoicePlayer shareVoicePlayer].currentRadioModel = currentRadioModel;
    [VoicePlayer shareVoicePlayer].curentIndex = indexPath.row;
    VoicePlayViewController *voicePlayVC = [[VoicePlayViewController alloc]init];
    [self presentViewController:voicePlayVC animated:YES completion:^{
        NSLog(@"跳转成功");
    }];
//    [self.navigationController pushViewController:voicePlayVC animated:YES];
    //下个界面的接口
//    [ModelSingleton shareModelSingleton].currentIndex = indexPath.row;
//    [ModelSingleton shareModelSingleton].currentRadioModel = currentRadioModel;
}

@end
